<cfif isDefined("url.id")>
	<cfset id = url.id>
<cfelseif isDefined("url.wsid")>
	<cfset id = url.wsid>
</cfif>

<cfscript>
	if ( uCase(client.DBMS) eq 'MSSQL')
		concat = '(PA.LASTNAME+, +PA.FIRSTNAME+" "+PA.MIDDLENAME)';
	else
		concat = 'concat(PA.LASTNAME,", ",PA.FIRSTNAME," ",PA.MIDDLENAME)';
</cfscript>

 
    
<cfquery name="getCreation" datasource="#client.company_dsn#">
	SELECT RECDATECREATED, RECCREATEDBY
    FROM CINWSFILE WHERE DOCNUMBER ='#ID#'
</cfquery>

<cfquery name="getHist" datasource="#client.company_dsn#">
 
	<cfif uCase(client.DBMS) eq 'MSSQL'>
     SELECT (PA.LASTNAME+', '+PA.FIRSTNAME+' '+PA.MIDDLENAME )AS NAME, 
    <cfelse>
      SELECT  concat(PA.LASTNAME,", ",PA.FIRSTNAME," ",PA.MIDDLENAME) AS NAME, 
    </cfif>
   
    PAT.DESCRIPTION, HI.DATELASTUPDATE, HI.TIMELASTUPDATE, HI.USERID, HI.REMARKS, HI.REFERENCEDATE
    
    FROM CINWSHISTORY HI
    
    LEFT JOIN CMFPA PA ON PA.PERSONNELIDNO = HI.PERSONNELIDNO
    LEFT JOIN CLKWSPATTERN  PAT ON PAT.PATTERNCODE = HI.PATTERNCODE
    
    WHERE 
    	WSDOCNUMBER = '#ID#'
    
    ORDER BY DATELASTUPDATE DESC, TIMELASTUPDATE DESC

</cfquery>

<cfset str = "">
<cfoutput query="getHist">
	<CFSET msg =''>
	<cfif remarks neq ''>
    	<cfset msg = " - [Remarks: #REMARKS#]">
    </cfif>
	<cfset str = str&DateFormat(DATELASTUPDATE,"MMM-DD")&' '&TimeFormat(TIMELASTUPDATE,"hh:mm:ss")&' : <b>'&#NAME#&'</b> Schedule on <b>'&DateFormat(REFERENCEDATE,"MMM. DD, YYYY") &'</b> was change to <b>'&DESCRIPTION&'</b> by ('&USERID&')'&msg&'. <BR />'>
</cfoutput>

<cfif getCreation.RecordCount>
	<cfset header = '#DateFormat(getCreation.RECDATECREATED,"MMM-DD")#:File Created by [<b>#getCreation.RECCREATEDBY#</b>]<br />'>
<cfelse>
	<cfset header = "">
</cfif>

<div style="width:100%; height:120px; overflow: auto; background:inherit" > 
  <cfoutput>#str##header#</cfoutput>
</div> 
